﻿#if UNITY_EDITOR
namespace JProfiler
{
    public class JProfiler
    {
        private JProfileData m_Data = new JProfileData();

        private bool m_Running = false;

        private static JProfiler m_Instance;

        public static JProfiler Instance
        {
            get
            {
                return m_Instance != null ? m_Instance : (m_Instance = new JProfiler());
            }
        }

        public void Record(string key, int type, long cost, long mem)
        {
            if (!m_Running) return;
            m_Data.Record(key, type, cost, mem);
        }

        public bool IsRunning
        {
            get
            {
                return m_Running;
            }
            set
            {
                if (m_Running == value) return;
                m_Running = value;
                if(m_Running)
                {
                    StartProfiling();
                }
                else
                {
                    StopProfiling();
                }
            }
        }

        public void StartProfiling()
        {
            ClearRecords();
            m_Data.StartTime = System.DateTime.Now;
        }

        public void StopProfiling()
        {
            m_Data.EndTime = System.DateTime.Now;
        }

        public void ClearRecords()
        {
            m_Data = new JProfileData();
        }


        public JProfileData Data
        {
            get
            {
                return m_Data;
            }
        }
    }
}
#endif